
package com.mp.chart.markerview;

import android.content.Context;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import com.mp.chart.components.MarkerView;
import com.mp.chart.data.Entry;
import com.mp.chart.data.KLineData;
import com.mp.chart.data.MinutesData;
import com.mp.chart.utils.StringUtils;
import com.android.R;

import java.text.DecimalFormat;

public class RightMarkerView extends MarkerView {

    private final boolean isOut;
    private DecimalFormat mFormat;
    private TextView tvContent;
    private String type;

    public RightMarkerView(String type, Context context, int layoutResource, boolean isOut, String format) {
        super(context, layoutResource);
        this.type = type;
        this.isOut = isOut;
        tvContent = (TextView) findViewById(R.id.tvContent);
        View body = findViewById(R.id.llBody);
        // if (mFormat != null)
        //mFormat = new DecimalFormat(format);
        // tvContent.setTextColor(mTheme.getStockChartBackgroundColor());
        tvContent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10f);
        body.setBackgroundResource(R.drawable.market_select_marker);


    }

    @Override
    public void refreshContent(Entry e, int dataSetIndex) {
        /*设置marker要显示的数据*/
        if ("kline".equals(type)) {
            KLineData data = (KLineData) e.getData();
            if (data != null) {
                tvContent.setText(StringUtils.doubleToDoubleString(data.percent) + "%");
            } else {
                tvContent.setText("");
            }
        } else if ("timeline".equals(type)) {
            MinutesData data = (MinutesData) e.getData();
            if (data != null)
                tvContent.setText(StringUtils.doubleToDoubleString(data.percentage) + "%");
            else {
                tvContent.setText("");
            }
        }
    }

    @Override
    public int getXOffset() {
        return isOut ? 0 : -getWidth();
    }

    @Override
    public int getYOffset() {
        return 0;
    }
 /*   @Override
    public int getXOffset() {
        return 0;
    }

    @Override
    public int getYOffset() {
        return 0;
    }*/
}
